/*
test for nothing....
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>

#include <interface.h>
#include "kv_pair.h"

int main()
{
	char config_file[512];
	char buf[1024];
	int i, fd;
	KV cur_kv;

	printf ("config_file:");
	scanf ("%s", config_file);

	fd=open("/tmp/kv_pair", O_RDWR | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP);

	KV_INIT(config_file);

	for (i=0; i<KV_MAX_CNT; i++)
	{
		read(fd, &cur_kv, sizeof(KV));
		KV_PUT( cur_kv.key, strlen(cur_kv.key), cur_kv.value, strlen(cur_kv.value) );
	}
	
	printf ("exiting...\n");
	KV_EXIT();
	return 0;
}





























void gen(char *p, int size, char c)
{
	int i;
	for (i=0; i<size; i++) p[i]=c;
}

#define PAGE_SIZE	128

void part_write()
{
	int i;
	char *p[4];
	for (i=0; i<4; i++)
	{
		p[i]=malloc(PAGE_SIZE*2);
		gen(p[i], PAGE_SIZE, 'a'+i);
	}
	sync_write_2(0, p, PAGE_SIZE, 3);

	for (i=0; i<4; i++) free(p[i]);
}

void part_read()
{
	char *p[4];
	int i;

	for (i=0; i<4; i++) p[i]=malloc(PAGE_SIZE*2);

	sync_read_2(0, p, PAGE_SIZE, 3);

	for (i=0; i<4; i++) printf ("%d, %c--%c\n", i, p[i][0], p[i][PAGE_SIZE-1]);
	
	for (i=0; i<4; i++) free(p[i]);
}


